<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    
    body {
        background-image: url(../JS素材/1.jpg);
    }
    
    #outer {
        /*body背景图片样式*/
        width: 100%;
        height: 1000px;
        background-size: 100%, 100%;
        background-repeat: no-repeat;
        position: absolute;
    }
    
    #in {
        width: 80%;
        height: 280px;
        margin: 0 auto;
        border: white 3px solid;
        margin-top: 300px;
        position: relative;
    }
    
    ul {
        display: flex;
        border: 1px white solid;
        list-style: none;
        cursor: pointer;
    }
</style>

<body>
    <div id='outer'>
        <div id='in'>
            <ul>
                <li><img src="../JS素材/1.jpg" width="303px" height="280px"></li>
                <li><img src="../JS素材/2.jpg" width="303px" height="280px"></li>
                <li><img src="../JS素材/3.jpg" width="303px" height="280px"></li>
                <li><img src="../JS素材/4.jpg" width="303px" height="280px"></li>
            </ul>
        </div>
    </div>
    <script>
        var imgs = document.querySelectorAll('img'); /*获取所有img标签元素*/
        for (var i = 0; i < imgs.length; i++) {
            imgs[i].onclick = function() { /*图像依次被存入数组imgs中，单击后激活事件*/
                document.body.style.backgroundImage = 'url(\"' + this.src + '\")'; /*此处是对body的背景图像更换*/
            }
        }
    </script>

</body>

</html>